package com.javaeye.dengyin2000.gwtmodel.client.ui;

import java.util.ArrayList;
import java.util.List;

import com.javaeye.dengyin2000.gwtmodel.client.model.PropertyModel;


public class PopulateForm {
	private List widgets;
	private Object object;
	public PopulateForm(Object object){
		this.object = object;
	}
	
	public PopulateForm addWidget(IPopulateWidget widget){
		if (widgets == null)
			widgets = new ArrayList();
		widget.setModel(new PropertyModel(object, widget.getName()));
		widgets.add(widget);
		return this;
	}
	
	
	public void populate(){
		if (widgets != null){
			for(int i=0;i<widgets.size(); i++){
				IPopulateWidget widget = (IPopulateWidget) widgets.get(i);
				widget.populateModel();
			}
		}
	}
	
}
